package single_game.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import single_game.logic.race_simulator.Race;

public class GuiMenu extends JMenuBar implements ActionListener {
	
	private static final long serialVersionUID = 1L;
	public JMenuItem x1, 
					 x2,
					 x4,
					 x8,
					 x12,
					 showProfile;
	public JMenu speed, profile;
	private RaceGui gui;
	
	public GuiMenu(RaceGui gui) {
		this.gui = gui;
		speed = new JMenu("speed");
		profile = new JMenu("profile");
		x1 = new JMenuItem("x1");
		x1.addActionListener(this);
		speed.add(x1);
		
		x2 = new JMenuItem("x2");
		x2.addActionListener(this);
		speed.add(x2);
		
		x4 = new JMenuItem("x4");
		x4.addActionListener(this);
		speed.add(x4);
		
		x8 = new JMenuItem("x8");
		x8.addActionListener(this);
		speed.add(x8);
		
		x12 = new JMenuItem("x12");
		x12.addActionListener(this);
		speed.add(x12);
		
		showProfile = new JMenuItem("show profile");
		showProfile.addActionListener(this);
		profile.add(showProfile);
		
		speed.setMnemonic(KeyEvent.VK_F);
		add(speed);		
		add(profile);
	}

	@Override
	public void actionPerformed(ActionEvent e) {		
		if (e.getSource() == x1) {
			Race.getInstance().stageSpeed = 1;
		}
		else if (e.getSource() == x2) {
			Race.getInstance().stageSpeed = 2;
		}
		else if (e.getSource() == x4) {
			Race.getInstance().stageSpeed = 4;
		}
		else if (e.getSource() == x8) {
			Race.getInstance().stageSpeed = 8;
		}
		else if (e.getSource() == x12) {
			Race.getInstance().stageSpeed = 12;
		}	
		else if (e.getSource() == showProfile) {
			gui.profileGui = new ProfileGUI();
		}
	}
}
